package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.Enum.ResultEnum;
import com.dongdongshop.core.SpecificPrint;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerServiceI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tbSellerController")
public class TbSellerController {

    private Logger logger= LoggerFactory.getLogger(TbBrandController.class);

    @Reference
    private TbSellerServiceI tbSellerServiceI;

    //跳转查询页面
    @RequestMapping("getFindAll")
    public String getFindAll(){
        return "admin/seller_1";
    }

    //查询商家审核表
    @RequestMapping("getFindAlls")
    @ResponseBody
    public List<TbSeller> getFindAlls(String name,String nickName){
        try {
            List<TbSeller> tbSellers = tbSellerServiceI.getFindAll(name,nickName);
            logger.info(ResultEnum.SUCCESS.getMessage()+"，查询结果为：{}",tbSellers);
            return tbSellers;
        }catch (Exception e){
            logger.error(ResultEnum.ERROR.getMessage()+":{}",e);
        }
       return  null;
    }

    //详情查询
    @RequestMapping("detailsQquery")
    @ResponseBody
    public TbSeller detailsQquery(String id){
        try {
            TbSeller tbSeller = tbSellerServiceI.detailsQquery(id);
            logger.info(ResultEnum.SUCCESS.getMessage()+"，查询结果为：{}",tbSeller);
            return tbSeller;
        }catch (Exception e){
            logger.error(ResultEnum.ERROR.getMessage()+":{}",e);
        }
        return null;
    }

    //修改审核通过
    @RequestMapping("approvedController")
    @ResponseBody
    public SpecificPrint examine1(String id){
        try {
            System.out.println(id);
            //查询当前选择信息进行set1
            TbSeller tbSeller = tbSellerServiceI.detailsQquery(id);
            tbSeller.setStatus("1");
            tbSellerServiceI.updateTbSeller(tbSeller);
            logger.info(ResultEnum.SUCCESS.getMessage()+"，参数为：{}",tbSeller);
            return SpecificPrint.response(ResultEnum.SUCCESS).setData(tbSeller);
        }catch (Exception e){
            logger.error(ResultEnum.ERROR.getMessage(),e);
            return SpecificPrint.response(ResultEnum.ERROR);
        }
    }
    //修改审核未通过
    @RequestMapping("auditFailedController")
    @ResponseBody
    public SpecificPrint auditFailedController(String id){
        try {
            TbSeller tbSeller = tbSellerServiceI.detailsQquery(id);
            tbSeller.setStatus("2");
            tbSellerServiceI.updateTbSeller(tbSeller);
            logger.info(ResultEnum.SUCCESS.getMessage()+"，参数为：{}",tbSeller);
            return SpecificPrint.response(ResultEnum.SUCCESS).setData(tbSeller);
        }catch (Exception e){
            logger.error(ResultEnum.ERROR.getMessage(),e);
            return SpecificPrint.response(ResultEnum.ERROR);
        }
    }

    //关闭删除商家审核
    @RequestMapping("deleteTbSeller")
    @ResponseBody
    public SpecificPrint deleteTbSeller(String id){
        try {
            tbSellerServiceI.deleteTbSeller(id);
            logger.info(ResultEnum.SUCCESS.getMessage()+"，参数为：{}",id);
            return SpecificPrint.response(ResultEnum.SUCCESS).setData(id);
        }catch (Exception e){
            logger.info(ResultEnum.ERROR.getMessage(),e);
            return SpecificPrint.response(ResultEnum.ERROR);
        }
    }
}
